package com.qinghe.plant.option;

import java.io.File;
import java.io.FileNotFoundException;

import org.springframework.util.ResourceUtils;

public class ManageOption {
	private static ManageOption instant = new ManageOption();

	public static ManageOption Instant() {
		return instant;
	}
	
	private String basemapPath;
	private String modelPath;

	public String getModelPath() {
		if (modelPath == null)
			modelPath = CreatModelPath();
		return modelPath;
	}

	public String getBasemapPath() {
		if(basemapPath==null)
			basemapPath=CreatBasemapPath();
		return basemapPath;
	}

	private ManageOption() {}

	private String CreatModelPath() {
		try {
			File path = new File(ResourceUtils.getURL("classpath:").getPath());
			if (!path.exists())
				path = new File("");

			// 如果上传目录为/asset/model/，则可以如下获取：
			File model = new File(path.getAbsolutePath(), "asset\\model\\");
			if (!model.exists())
				model.mkdirs();
			System.out.println("upload url:" + model.getAbsolutePath() + "\\");
			return model.getAbsolutePath() + "\\";
		} catch (FileNotFoundException e) {
			return null;
		}
	}
	
	private String CreatBasemapPath() {
		try {
			File path = new File(ResourceUtils.getURL("classpath:").getPath());
			if (!path.exists())
				path = new File("");

			// 如果上传目录为/asset/basemap/，则可以如下获取：
			File basemap = new File(path.getAbsolutePath(), "asset\\basemap\\");
			if (!basemap.exists())
				basemap.mkdirs();
			System.out.println("upload url:" + basemap.getAbsolutePath() + "\\");
			return basemap.getAbsolutePath() + "\\";
		} catch (FileNotFoundException e) {
			return null;
		}
	}


}
